package com.example.service;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
 * @program: springcloud
 * @description: ribbon实现层
 * @author: ChenZhiXiang
 * @create: 2019-06-03 15:04
 **/
@Service
public class HelloServiceImpl {

    @Autowired
    private RestTemplate restTemplate;

    @HystrixCommand(fallbackMethod = "hiError")
    public String hystrix(){
        return restTemplate.getForObject("http://service-hi/hi",String.class);
    }

    public String hiError() {
        return "hi,服务出错，ribbon断路器启动，,sorry,error!";
    }
}
